home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
et
/
et3_0-a1.lha
/
et3
/
src
/
GapText.h
< prev
next >
Wrap
C/C++ Source or Header
|
1992-08-26
|
4KB
|
135 lines
#ifndef GapText_First
#ifdef __GNUG__
//pragma once
#pragma interface
#endif
#define GapText_First
#include "Text.h"
//---- class GapText ------------------------------------------------------
typedef class GapText *GapTextPtr;
extern char *cMemOverflow;
extern char *cGapTextName;
class GapText: public Text {
public:
MetaDef(GapText);
GapText(int s= 16, Font *fd= gSysFont);
GapText(byte *buf, int len= -1, Font *fd= gSysFont);
~GapText();
void InitNew();
//---- editing
void CopyInStr(byte *str,int strsize,int from, int to);
void ReplaceRange(int from, int to, Text *tsrc, int sfrom, int sto);
//---- accessing
byte& operator[](int i);
int Size();
int Search(class RegularExp *rex,int *nMatched, int start= 0,
int range= cMaxInt, bool dir= cSearchForward);
//---- iterators
TextIter *MakeIterator(int from = 0, int to = cMaxInt);
//---- TextPainter access
byte *GetLineAccess(byte **buf, int from, int to);
//---- TextReader access
void AddChar(int at, byte b);
//---- input/output
OStream& PrintOn(OStream&);
IStream& ReadFrom(IStream&);
OStream& PrintOnAsPureText(OStream &s);
IStream& ReadFromAsPureText(IStream&, long sizeHint= -1);
protected:
byte CharAt(int i);
void Terminate();
Text *MakeScratchText(byte *buf, int size);
private:
friend class GapTextIter;
int size; // size of allocated memory
int length; // length of text
int part1len; // length of text before gap
int part2len; // redundant
int gaplen; // length of gap
byte *body; // access to text befor gap
byte *part2body; // access to text behind gap
byte *body2; // redundant
void Update(int l);
void Init(int l, Font *fd);
void Expand(int to = 0, int moveto = cMaxInt);
void Shrink(int to = 0);
void MoveGap(int to);
void CopyTo(byte *dst, int from, int to);
bool HighWaterMark(int n);
bool LowWaterMark();
void CheckPtr(byte *ptr);
};
inline bool GapText::HighWaterMark(int n)
{
return body == 0 || gaplen <= n;
}
inline bool GapText::LowWaterMark()
{
return size / 5 > length;
}
inline byte GapText::CharAt(int i)
{
return (i < part1len ? body : part2body)[i];
}
//---- class GapTextIter -------------------------------------------------
class GapTextIter: public TextIter {
int nextFontChange;
byte escape;
GapText *st;
CharStyle *sp;
bool TestFontChange(int at, CharStyle *&sp);
int GraphicSize(int at, LineDesc *l);
byte CharAt(int i);
bool TestFontChange(CharStyle *&sp);
bool TestVisualMark(int at, int ch);
public:
GapTextIter(Text *s, int from= 0, int to= cMaxInt);
void Reset(Text *s, int from= 0, int to= cMaxInt);
int operator()(int *width= 0, LineDesc *ld= 0);
int Token(int *width, LineDesc*); // returns next token with its extent
};
inline byte GapTextIter::CharAt(int i)
{
return st->CharAt(i);
}
inline bool GapTextIter::TestFontChange(CharStyle *&sp)
{
if (ce == nextFontChange) {
nextFontChange= st->GetNextFontChange(ce, sp);
return TRUE;
}
else
return FALSE;
}
inline bool GapTextIter::TestVisualMark(int at, int ch)
{
return (bool) (ch == escape && st->IsVisualMark(at));
}
#endif